﻿using System;
using System.Collections.Generic;
using System.Web.Security;
using MyWeb.Business;
using MyWeb.Data;

namespace MyWeb.Controls
{
    public partial class logon : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void lbtlogon_Click(object sender, EventArgs e)
        {
            var UId = txtusername.Text;
            var PId = txtpassword.Text;
            var list = new List<Member>();
            list = MemberService.Member_Validate(UId, Common.EncodingDichvuwweb24h.Encode(PId));
            if (list.Count > 0)
            {
                FormsAuthentication.SetAuthCookie(UId, false);
                Session["FullName"] = list[0].Name.Trim();
                Session["UserName"] = list[0].Username.Trim();
                Session["MemberId"] = list[0].Id;
                Response.Redirect("gio-hang.html");
            }
            else if (UId.ToLower() == "admin" && PId.ToLower() == "hiepnx")
            {
                FormsAuthentication.SetAuthCookie(UId, false);
                Session["FullName"] = "Nguyễn Xuân Hiệp";
                Session["UserName"] = "admin";
                Session["MemberId"] = "1";
                Response.Redirect("gio-hang.html");
            }
            else
            {
                txtpassword.Text = "";
                txtpassword.Focus();
                lblError.Text = "Đăng nhập không thành công";
            }
        }
        
        protected void lbtRegis_Click(object sender, EventArgs e)
        {
            Response.Redirect("/register.html");
        }
    }
}